package Operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created by Salted fish
 * Description:
 * User: 24539
 * Date：2021-09-22
 * Time: 15:46
 */
public class AddOperation implements Opface{
    @Override
    public void work(BookList bookList) {
        System.out.println("添加图书 ");
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入图书的名字： ");
        String name = scanner.next();
        System.out.println("请输入图书的作者： ");
        String author = scanner.next();
        System.out.println("图书的类型");
        String type = scanner.next();
        System.out.println("图书的价格");
        int price = scanner.nextInt();
        Book book = new Book(name,author,type,price);

        //存放
        int size = bookList.getUsedSize();
        for(int i = 0; i<size;i++) {
            Book book1 = bookList.getBook(i);
            if(book1.getName().equals(name)) {
                System.out.println("已经存在这本书");
                return;
            }
        }
        bookList.setBooks(size,book);
        bookList.setUsedSize(size+1);
        System.out.println("新增图书成功");
    }
}
